from rest_framework import status
from rest_framework.decorators import api_view, permission_classes
from rest_framework.permissions import AllowAny
from rest_framework.response import Response

from user.serializers import RegisterSerializer


@api_view(['POST'])
@permission_classes([AllowAny])
def user_register(request):
    """
    用于用户注册的视图函数
    """
    s = RegisterSerializer(data=request.data)
    if s.is_valid():
        s.save()
        return Response(data=s.data, status=status.HTTP_201_CREATED)
    return Response(s.errors, status=status.HTTP_400_BAD_REQUEST)
